import axios from '@/libs/api.request'
import {
    rejects
} from 'assert';
const USER_MAP = {
    super_admin: {
        name: 'super_admin',
        user_id: '1',
        access: ['super_admin', 'admin'],
        token: 'super_admin',
        avator: 'https://file.iviewui.com/dist/a0e88e83800f138b94d2414621bd9704.png'
    },
    admin: {
        name: 'admin',
        user_id: '2',
        access: ['admin'],
        token: 'admin',
        avator: 'https://avatars0.githubusercontent.com/u/20942571?s=460&v=4'
    }
}

export const login = ({
    userName,
    password
}) => {
    return new Promise((reslove, reject) => {
        let data = {
            code: 200,
            data: {
                token: USER_MAP[userName].token
            },
            msg: ''
        }
        setTimeout(() => {
            reslove(data)
        }, 1000);

    })
}

export const getUserInfo = (token) => {
    return new Promise((reslove, reject) => {
        for (const res in USER_MAP) {
            if (USER_MAP[res].token == token) {
                let data = {
                    code: 200,
                    data: USER_MAP[res],
                    msg: ''
                }
                reslove(data)
            }
        }

    })

}

export const logout = (token) => {
    return axios.request({
        url: 'logout',
        method: 'post'
    })
}
